package com.potenza.training.resume.controller;

import com.potenza.training.resume.entity.EducationExperienceEntity;
import com.potenza.training.resume.service.EducationExperienceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 教育经历
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-15 20:23:25
 */
@RestController
@RequestMapping("resume/educationexperience")
public class EducationExperienceController {
    @Autowired
    private EducationExperienceService educationExperienceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("resume:educationexperience:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = educationExperienceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("resume:educationexperience:info")
    public R info(@PathVariable("id") Long id){
		EducationExperienceEntity educationExperience = educationExperienceService.getById(id);

        return R.ok().put("educationExperience", educationExperience);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("resume:educationexperience:save")
    public R save(@RequestBody EducationExperienceEntity educationExperience){
		educationExperienceService.save(educationExperience);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("resume:educationexperience:update")
    public R update(@RequestBody EducationExperienceEntity educationExperience){
		educationExperienceService.updateById(educationExperience);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("resume:educationexperience:delete")
    public R delete(@RequestBody Long[] ids){
		educationExperienceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 回显
     */
    @RequestMapping("/findByresumeId/{resumeId}")
    @RequiresPermissions("resume:educationexperience:findByresumeId")
    public R findByresumeId(@PathVariable("resumeId") Integer resumeId){
        List<EducationExperienceEntity> educationList =  educationExperienceService.findByresumeId(resumeId);

        return R.ok().put("educationList",educationList);
    }

    /**
     * 删除单个
     */
    @RequestMapping("/deleteById/{id}")
    @RequiresPermissions("resume:educationexperience:deleteById")
    public R deleteById(@PathVariable("id") Integer id){
        educationExperienceService.removeById(id);

        return R.ok();
    }
}
